﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Manage.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="B2B.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<h2>ProductUpdatePostBuyRequest</h2>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HEAD" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="main_content" runat="server">
    <script type="text/javascript">
        function loadDanhMuc(maLinhVuc) {
            if (maLinhVuc != 0) {
                $.getJSON("/Home/DanhSachDanhMuc?id=" + maLinhVuc,
                 function (data) {
                     document.getElementById("checkCategory").innerText = "";
                     var s = '';
                     s += "<select id='MaDanhMuc'>";
                     for (i = 0 ; i < data.length; i++) {
                         s += "<option value='" + data[i].MaDanhMuc + "'>" + data[i].TenDanhMuc + "</option>";
                     }
                     s += "</select>";
                     $("#divDanhMuc").html(s);
                 });
            }
            else {
                document.getElementById("checkCategory").innerText = "Please select a item in category";
            }
        }



        function CheckAndUpdate() {
            
            var quantity = document.getElementById("SoLuongCanMua");
            var productname = document.getElementById("TenSanPham");
            var category = document.getElementById("selProductCategory");
            var detail = document.getElementById("ChiTiet");
            var file = document.getElementById("HinhAnh");
            var ma = document.getElementById("hidMaSPMua");
    
            if (productname.value == "") {
                document.getElementById("checkProductName").innerText = "Please enter product name";
                productname.focus();
                return;
            }
            else {
                document.getElementById("checkProductName").innerText = "";
            }

            if (category.value == 0) {
                document.getElementById("checkCategory").innerText = "Please select a item in category";
                category.focus();
                return;
            }
            else {
                document.getElementById("checkCategory").innerText = "";
            }

            if (quantity.value == "") {
                document.getElementById("CheckQuantity").innerText = "Please enter estimated order quantity";
                quantity.focus();
                return;
            }
            else {
                document.getElementById("CheckQuantity").innerText = "";
            }
            //alert("ten sp=" + productname.value);
            //alert("ma dm=" + category.value);
            //alert("sl cm=" + quantity.value);
            alert("hinh anh=" + file.value);
            //alert("ten hinh=" + tenhinh);
            //alert("chi tiet=" + detail.value);
            //alert("ma spmua = " + ma.value);

                var json = {
                    TenSanPham: productname.value,
                    MaDanhMuc: category.value,
                    SoLuongCanMua: quantity.value,
                    HinhAnh: file.value,
                    TenHinh: file.files[0].name,
                    MaThanhVien: 1,
                    ChiTiet: detail.value,
                    TinhTrang: false,
                    MaSanPhamMua: ma.value
                };

            $.ajax({
                url: '/Product/ProductUpdatePostBuyRequest',
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify(json),
                success: function (response) {
                    alert(response);
                }
            });
            //alert("cuoi ham");
        }
    </script>
    <form name="form1" id="form1" runat="server">
        
    <!--Bắt đầu post a buying request-->
    <div align="left">
        <div>Update post buy request</div>
        <div>
            <!--Bắt đầu bảng post a buying Request-->
            <% var sp = ((PostBuyRequest)((ArrayList)ViewData["SPMua"])[0]); %>
            <table>
                <tr>
                    <th style="width: 280px">Product Name:</th>
                    <td style="width: 228px"><input type="text" id="TenSanPham" value="<%=sp.TenSanPham %>"/></td>
                    <td style="width: 519px"><div id="checkProductName" style="color: red"></div></td>
                </tr>

                <tr>
                    <th style="width: 280px; height: 62px;">Product Category: </th>
                    <!--Tu viet group box bang javascript de chon muc mua hang-->
                    
                    
                    <td style="width: 228px; height: 62px;">
                            <select ID="selProductCategory">
                                <option value="0">--Please select category--</option>
                                <%foreach(var lv in (ArrayList)ViewData["linhvuc"]) 
                                  {%>                             
                                    <option onclick="loadDanhMuc('<%=((LinhVuc)lv).MaLinhVuc.ToString() %>')" value="<%=((LinhVuc)lv).MaLinhVuc.ToString() %>"><%=((LinhVuc)lv).TenLinhVuc.ToString() %></option>
                                <%}%>
                            </select>
                            <div id="divDanhMuc"></div>
                            </td>
                    <td style="width: 519px; height: 62px;">
                        <div id="checkCategory" style="color: red"></div>
                        
                    </td>
                </tr>

                 <tr>
                    <th style="height: 91px; width: 280px;">Product Detailed Specification: </th>
                   
                    <td style="height: 91px; width: 228px;"><textarea cols="50" rows="5" id="ChiTiet"><%=sp.ChiTiet %></textarea></td>
                   
                    <td style="height: 91px; width: 519px;">&nbsp;</td>
                </tr>

                <tr>
                    <th style="height: 35px; width: 280px;">Relevant Files to the Request: </th>
                    <td style="height: 35px; width: 228px;">
                        <input id="HinhAnh" style="width: 81%; height: 30px; margin-top: 5px;" type="file" />
                        <br />
                    </td>
                    <td style="height: 35px; width: 519px;">
                        &nbsp;</td>
                </tr>

                <tr>
                    <th style="width: 280px">Estimated Order Quantity: </th>
                    <td style="width: 228px">
                        <table>
                            <tr>
                                <td style="height: 42px"><input type="number" id="SoLuongCanMua" value="<%=sp.SoLuongCanMua %>"/></td>
                            </tr>
                        </table>
                    </td>
                    <td style="width: 519px">
                        <div ID="CheckQuantity" style="color: red"></div></td>
                </tr>
                  
               <tr>
                  <td style="width: 280px"></td>
                   <td style="width: 228px">
                       <input type="button" value="Update" onclick="CheckAndUpdate()"/>
                       <input type="hidden" value="<%=sp.MaSanPhamMua.ToString() %>" id="hidMaSPMua"/>
                   </td>
               </tr>

            </table>
            <!--Kết thúc bảng post a buying Request-->
        </div>
    </div>
    <!--Kết thúc post a buying request-->
    </form>


    <!-- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA-->

     <div align="left">            
        <div align="center">
            <!--Bắt đầu bảng post a buying Request-->
            <form onsubmit="return CheckAndSend()" method="post" action="/Product/ProductPostBuyRequest" enctype="multipart/form-data">
                <table border="1">
                    <tr>
                        <th align="center" colspan="3"><div><h4>Tell The Supplier What You Want</h4></div></th>
                    </tr>
                    <tr>
                        <th style="width: 280px">Product Name:</th>
                        <td style="width: 228px"><input type="text" id="Text1" name="tenSanPham" /></td>
                        <td style="width: 519px"><div id="Div1" style="color: red"></div></td>
                    </tr>

                    <tr>
                        <th style="width: 280px; height: 62px;">Product Category: </th>
                        <!--Tu viet group box bang javascript de chon muc mua hang-->
                    
                    
                        <td style="width: 228px; height: 62px;">
                                <select ID="Select1">
                                    <option value="0">--Please select category--</option>
                                    <%foreach(var lv in (ArrayList)ViewData["linhvuc"]) 
                                      {%>                             
                                        <option onclick="loadDanhMuc('<%=((LinhVuc)lv).MaLinhVuc.ToString() %>')" value="<%=((LinhVuc)lv).MaLinhVuc.ToString() %>"><%=((LinhVuc)lv).TenLinhVuc.ToString() %></option>
                                    <%}%>
                                </select>
                                <div id="div2"></div>
                                </td>
                        <td style="width: 519px; height: 62px;">
                            <div id="Div3" style="color: red"></div>
                        
                        </td>
                    </tr>

                     <tr>
                        <th style="height: 91px; width: 280px;">Product Detailed Specification: </th>
                   
                        <td style="height: 91px; width: 228px;"><textarea cols="50" rows="5" id="Textarea1" name="chiTiet"></textarea></td>
                   
                        <td style="height: 91px; width: 519px;">&nbsp;</td>
                    </tr>

                    <tr>
                        <th style="height: 35px; width: 280px;">Relevant Files to the Request: </th>
                        <td style="height: 35px; width: 228px;">
                              <input id="File1" name="fileUpload" style="width: 81%; height: 30px; margin-top: 5px;" type="file" />
                     
                             <input type="hidden" name="maThanhVien" value="1" />
                            <br />
                        </td>
                        <td style="height: 35px; width: 519px;">
                            &nbsp;</td>
                    </tr>

                    <tr>
                        <th style="width: 280px">Estimated Order Quantity: </th>
                        <td style="width: 228px">
                            <table>
                                <tr>
                                    <td style="height: 42px"><input type="number" id="Number1" onkeypress="return onlyNumbers(event)" name="soLuongCanMua" /></td>
                                </tr>
                            </table>
                        </td>
                        <td style="width: 519px">
                            <div ID="Div4" style="color: red"></div></td>
                    </tr>
                  
                   <tr>
                      <td style="width: 280px"></td>
                      <td style="width: 228px"><input type="submit" value="Send" id="send"/></td>
                      <td style="width: 519px"><a href="/Product/ProductWatchPostBuyRequest?id=1">danh sách yêu cầu</a></td>
                   </tr>

                </table>
            </form>
            <!--Kết thúc bảng post a buying Request-->
        </div>
    </div>
    <!--Kết thúc post a buying request-->


</asp:Content>
